package com.gotrade.demo.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author jason.tang
 * @create 2018-12-06 10:17
 * @description 服务端
 */

public class NettyServer {
    public static void main(String[] args) {
        ServerBootstrap bootstrap = new ServerBootstrap();

        NioEventLoopGroup bossGrp = new NioEventLoopGroup();
        NioEventLoopGroup workerGrp = new NioEventLoopGroup();

        bootstrap.group(bossGrp, workerGrp)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    protected void initChannel(NioSocketChannel serverChannel) throws Exception {
                        ChannelPipeline pipeline = serverChannel.pipeline();
                        pipeline.addLast(new ServerHandler());
                    }
                });
        bootstrap.bind("localhost",9909);
    }
}